<template>
  <el-form-item :label="labelName" :prop="rulesId">
    <!-- 子组件使用v-model绑定select_Value组件 -->
    <el-select
      v-model="select_Value"
      placeholder="请选择"
      :multiple="Open"
      :filterable="Open"
      :allow-create="Open"
      :default-first-option="Open"
      style="width: 400px"
    >
      <!-- v-for 遍历父传入的数据,并渲染 -->
      <el-option
        v-for="item in dateList"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      />
    </el-select>
  </el-form-item>
</template>

<script>
export default {
  name: 'SelectMode',
  props: {
    // 接收父传入的数据
    // 使用value 接收父级当前的值
    dateList: {
      type: [Array],
      required: true
    },
    value: {
      type: [Number, String, Array],
      required: true
    },
    labelName: {
      type: [String],
      required: true
    },
    isOpen: [Boolean],
    rulesId: {
      type: [String],
      default: ''
    }
  },
  data() {
    return {
      Open: this.isOpen || false
    }
  },
  // 计算属性select_Value与下拉组件双向绑定
  computed: {
    select_Value: {
      // 当点击某一项时,通过自定义事件input传出当前值
      set(val) {
        this.$emit('input', val)
      },
      get() {
        // 将父级当前的值返回出来直接影响当前页面
        return this.value
      }
    }
  }
}
</script>

<style>
</style>
